package day7zy;

import java.util.ArrayList;

/**
 * @author oldliu
 * @since 1.0
 */
public class JavaClass {
    String name;//名称
    String teacher;
    String dirTeacher;//
    String start;//开班时间
    //存放班级学生姓名，类似数组
    ArrayList<String> stus = new ArrayList<>();

    //加新生
    public void add(String name) {
        if (stus.contains(name)) {
        } else {
            stus.add(name);
        }
    }


    //显示班级的信息
    public void show() {
        System.out.println("班级名称:" + name);
        System.out.println("指导老师:" + teacher + ",班主任：" + dirTeacher);
        System.out.println("学生信息如下：");
        System.out.println(stus);
    }

    //找学生在不在这个班级
    public boolean search(String name) {
        for (int i = 0; i < stus.size(); i++) {
            if (name.equals(stus.get(i)))
                return true;
        }
        return false;
    }
   //班级人数
    public int sum() {
        int sum = 0;
        for (int i = 0; i < stus.size(); i++) {
            sum++;
        }return sum;
    }


    //查找指定位置学生姓名
    public String find(int index) {
        String mz = " ";
        for (int i = 0; i < stus.size(); i++) {
            if (index == i) {
                mz = stus.get(index);
            }
        }return mz;
    }


    //修改学生姓名
    public void xgxm(String jxm,String xxm) {
        int jwz = stus.indexOf(jxm);
        stus.remove(jxm);
        if (stus.contains(xxm)) {
        } else {
            stus.add(jwz, xxm);
        }
    }

    //在区间范围内找人
    public boolean search1(int start, int end, String name) {
            for (int j = start; j < end&&j<stus.size(); j++) {
                if (name.equals(stus.get(j))&&start>0)
                    return true;
            }return false;
        }
    }
